/******************通告栏边距自适应******************/
/**
 *  通告栏要和鼠标移动出现的通告栏出现通信
 **/
let adjustBorder = function (className, parentClassName, direct, func) {
    this.className = className;
    this.parentClassName = parentClassName;
    this.direct = direct;
    this.func = func;
};
adjustBorder.prototype.adjust = function () {
    let node = getClass(this.className)[0];
    let pare = getClass(this.parentClassName)[0];
    if (this.direct === "right") {
        node.style.right = -pare.offsetWidth + node.clientWidth + "px";
    } else if (this.direct === "bottom") {
        node.style.bottom = -pare.offsetHeight + node.clientWidth + "px";
    }
};
let info = new adjustBorder("message-content-wrapperRight", "message-content", "right");
info.adjust();

/********************鼠标移动出现*******************/
let userFrame = function (nodeArr) {
    this.nodeArr = nodeArr;
    this.frameArr = [];
};

userFrame.prototype.setFunc = function () {
    for (let i = 0, j = 0; i < this.nodeArr.length; i++, j++) {
        let point = getClass(this.nodeArr[i].aimNode)[0];
        if (j < arguments.length && arguments) {
            if (point === getClass(arguments[j].func)[0]) {
                point.adjust(arguments[j].adjust());
            }
        }
    }
};
userFrame.prototype.getFrameArr = function (aim) {
    for (let i = 0; i < this.nodeArr.length; i++) {
        let aimNode = getClass(this.nodeArr[i].aimNode)[0];
        if (aimNode !== aim) {
            if (aimNode.style.display === "block") {
                aimNode.style.display = "none";
            } else {
                aimNode.style.display = "none";
            }
        }
    }
};

userFrame.prototype.showUserFrame = function () {
    for (let i = 0; i < this.nodeArr.length; i++) {
        let point = getClass(this.nodeArr[i].pointNode)[0];
        let aim = getClass(this.nodeArr[i].aimNode)[0];
        let that = this;
        point.onclick = function (event) {
            that.getFrameArr(aim);
            if (aim.style.display === "" || aim.style.display === "none")
                aim.style.display = "block";
            else {
                aim.style.display = "none";
            }
            event.preventDefault();
        };
    }
};
let arr = [];
/*右上角用户登录状态显示*/
arr.push({
    pointNode: "user-getInfo",
    aimNode: "user-nav"
});
/*通告栏显示*/
arr.push({
    pointNode: "fa fa-bell-o",
    aimNode: "message"
});
// /*分享右上角的弹出框*/
// arr.push({
//     pointNode: "fa fa-ellipsis-h",
//     aimNode: "more-choice-frame"
// });
let userFr = new userFrame(arr);
userFr.setFunc(info);
userFr.getFrameArr();
userFr.showUserFrame();

